﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using LazyKex;

namespace TestProject1
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class UnitTest1
    {
        public UnitTest1()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestMethod1()
        {
            string fileContent = @"

S

K

I

S

II


";

            
            LazyKDislexic dislexic = new LazyKDislexic(fileContent);
            char[] tokensEsperados = new char[]{'S', 'K', 'I', 'S', 'I', 'I'};
            int current = 0;
            while(dislexic.HasMoreTokens())
            {
                Assert.AreEqual(tokensEsperados[current], dislexic.NextToken());
                current++;
            }

            Assert.AreEqual(tokensEsperados.Length, current);
            Assert.IsFalse(dislexic.HasMoreTokens());

        }


        [TestMethod]
        public void TestMethod2()
        {
            string fileContent = @"SKskIi()*`01";


            LazyKDislexic dislexic = new LazyKDislexic(fileContent);
            char[] tokensEsperados = fileContent.ToCharArray();
            int current = 0;
            while (dislexic.HasMoreTokens())
            {
                Assert.AreEqual(tokensEsperados[current], dislexic.NextToken());
                current++;
            }

            Assert.AreEqual(tokensEsperados.Length, current);
            Assert.IsFalse(dislexic.HasMoreTokens());

        }

        [TestMethod]
        public void TestMethod3()
        {
            string fileContent = @"sssssss7";


            LazyKDislexic dislexic = new LazyKDislexic(fileContent);
            char[] tokensEsperados = fileContent.ToCharArray();
            int current = 0;
            while (dislexic.HasMoreTokens())
            {
                if (tokensEsperados[current] == '7')
                {
                    try
                    {
                        dislexic.NextToken();
                        Assert.IsTrue(false, "leu token 7 sem erro");
                    }
                    catch (Exception) { Assert.IsTrue(true, "jogou excecao para token 7"); }
                    break;
                }
                
                Assert.AreEqual(tokensEsperados[current], dislexic.NextToken());
                current++;
            }


        }


        // teste simples, combinator
        [TestMethod]
        public void TestMethod4()
        {
            string fileContent = @"SKIISK";


            LazyKDislexic dislexic = new LazyKDislexic(fileContent);
            SyntaticLazyKex syntatic = new SyntaticLazyKex(dislexic);


            Assert.IsTrue(syntatic.TryAnalyse());

            string code = syntatic.GetCode();


        }

        // teste com escopo
        [TestMethod]
        public void TestMethod5()
        {
            string fileContent = @"SK(I)I";//(((S)))KS(I(S)KS(I))";


            LazyKDislexic dislexic = new LazyKDislexic(fileContent);
            SyntaticLazyKex syntatic = new SyntaticLazyKex(dislexic);


            Assert.IsTrue(syntatic.TryAnalyse());

            string code = syntatic.GetCode();


        }

        // teste com escopo
        [TestMethod]
        public void TestMethod6()
        {
            string fileContent = @"SK(I)I(((S)))KS(I(S)KS(I))";


            LazyKDislexic dislexic = new LazyKDislexic(fileContent);
            SyntaticLazyKex syntatic = new SyntaticLazyKex(dislexic);


            Assert.IsTrue(syntatic.TryAnalyse());

            string code = syntatic.GetCode();


        }


        [TestMethod]
        public void TestMethod7()
        {
            string fileContent = @"0110011";


            LazyKDislexic dislexic = new LazyKDislexic(fileContent);
            SyntaticLazyKex syntatic = new SyntaticLazyKex(dislexic);


            Assert.IsTrue(syntatic.TryAnalyse());

            string code = syntatic.GetCode();


        }


        [TestMethod]
        public void TestMethod8()
        {
            string fileContent = @"*iks";


            LazyKDislexic dislexic = new LazyKDislexic(fileContent);
            SyntaticLazyKex syntatic = new SyntaticLazyKex(dislexic);


            Assert.IsTrue(syntatic.TryAnalyse());

            string code = syntatic.GetCode();


        }

        [TestMethod]
        public void TestMethod9()
        {
            string fileContent = @"*iks*";


            LazyKDislexic dislexic = new LazyKDislexic(fileContent);
            SyntaticLazyKex syntatic = new SyntaticLazyKex(dislexic);


            Assert.IsFalse(syntatic.TryAnalyse());

            string code = syntatic.GetCode();


        }



    }
}
